﻿
namespace NamedBinaryTag
{
	/// <summary>
	/// Represents a Tag containing a short.
	/// </summary>
	public sealed class TagShort : NamedTag, IValueTag<short>
	{
		private short _value;

		public short Value
		{
			get { return _value; }
			set { if (_value != value) { _value = value; RaisePropertyChange("Value"); } }
		}

		public override byte TagType
		{
			get { return 2; }
		}

		public override void Read(System.IO.BinaryReader input, bool ignoreName)
		{
			base.Read(input, ignoreName);
			Value = ByteReverser.Reverse(input.ReadInt16());
		}

		public override void Write(System.IO.BinaryWriter output, bool ignoreName)
		{
			base.Write(output, ignoreName);
			output.Write(ByteReverser.Reverse(Value));
		}

		public override string ToString()
		{
			return string.Format("TagShort {{ Name = \"{0}\", Value = {1} }}", Name, _value);
		}
	}
}
